import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';

import Home from '../views/home.vue';
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const routes: RouteRecordRaw[] = [
    {
        path: '/',
        redirect: '/page',
    },
    {
        path: '/',
        name: 'Home',
        component: Home,
        children: [
            {
                path: '/page',
                name: 'pageTable',
                meta: {
                    title: '页面列表',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/pageTable.vue'),
            },
            {
                path: '/subscribe',
                name: 'subscribe',
                meta: {
                    title: '页面列表',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/SubscribeTable.vue'),
            },
            {
                path: '/pressContact',
                name: 'pressContact',
                meta: {
                    title: '页面列表',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/PressContactTable.vue'),
            },
            {
                path: '/articlePage',
                name: 'articleTable',
                meta: {
                    title: '页面列表',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/articleTable.vue'),
            },
            {
                path: '/milestonePage',
                name: 'milestoneTable',
                meta: {
                    title: '页面列表',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/milestoneTable.vue'),
            },
            {
                path: '/articleEditor',
                name: 'articleEditor',
                meta: {
                    title: '文章列表',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/edit/article-editor.vue'),
            },
            {
                path: '/modelEditor',
                name: 'modelEditor',
                meta: {
                    title: '车型页面编辑',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/edit/model-editor.vue'),
            },
            {
                path: '/mainInfoEditor',
                name: 'mainInfoEditor',
                meta: {
                    title: '主要信息编辑',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/edit/main-info-editor.vue'),
            },
            {
                path: '/milestoneEditor',
                name: 'milestoneEditor',
                meta: {
                    title: '历史新闻编辑',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/edit/milestone-editor.vue'),
            },
            {
                path: '/homeEditor',
                name: 'homeEditor',
                meta: {
                    title: '主要信息编辑',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/edit/home-editor.vue'),
            },
            {
                path: '/mod',
                name: 'modTable',
                meta: {
                    title: '模板',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/modTable.vue'),
            },
            {
                path: '/image',
                name: 'image',
                meta: {
                    title: '图片资源',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/imageTable.vue'),
            },
            {
                path: '/videos',
                name: 'videos',
                meta: {
                    title: '视频资源',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/videoTable.vue'),
            },
            {
                path: '/pdf',
                name: 'pdf',
                meta: {
                    title: '文章资源',
                },
                component: () => import(/* webpackChunkName: "table" */ '../views/pdfTable.vue'),
            },

            {
                path: '/user',
                name: 'user',
                meta: {
                    title: '个人中心',
                },
                component: () => import(/* webpackChunkName: "user" */ '../views/user.vue'),
            },

        ],
    },
    {
        path: '/login',
        name: 'Login',
        meta: {
            title: '登录',
        },
        component: () => import(/* webpackChunkName: "login" */ '../views/login.vue'),
    },
    {
        path: '/403',
        name: '403',
        meta: {
            title: '没有权限',
        },
        component: () => import(/* webpackChunkName: "403" */ '../views/403.vue'),
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    NProgress.start();
    // const role = localStorage.getItem('ms_username');
    // const permiss = usePermissStore();
    // if (!role && to.path !== '/login') {
    //     next('/login');
    // } else if (to.meta.permiss && !permiss.key.includes(to.meta.permiss)) {
    //     // 如果没有权限，则进入403
    //     next('/403');
    // } else {
    //     next();
    // }
    next();
});

router.afterEach(() => {
    NProgress.done()
})

export default router;
